package com.woniuxy.oldobject.service.impl;

import com.woniuxy.oldobject.dao.ElderInfoDao;
import com.woniuxy.oldobject.dto.ElderDto;
import com.woniuxy.oldobject.entity.ElderInfo;
import com.woniuxy.oldobject.service.ElderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 老人service层实现类
 * @Title: ElderServiceImpl
 * @Package com.woniuxy.oldobject.service.impl
 * @Author: LSL
 * @CreateTime: 2022/7/25 15:28
 */
@Service
public class ElderInfoServiceImpl implements ElderInfoService {
    @Autowired
    ElderInfoDao elderInfoDao;

    @Override
    public ElderInfo queryById(Integer id) {
        return elderInfoDao.queryById(id);
    }

    @Override
    public List<ElderInfo> queryAllByLimit(ElderInfo elderInfo, Pageable pageable) {
        return elderInfoDao.queryAllByLimit(elderInfo, pageable);
    }

    @Override
    public long count(ElderInfo elderInfo) {
        return elderInfoDao.count(elderInfo);
    }

    @Override
    public int insert(ElderInfo elderInfo) {
        return elderInfoDao.insert(elderInfo);
    }

    @Override
    public int insertBatch(List<ElderInfo> entities) {
        return elderInfoDao.insertBatch(entities);
    }

    @Override
    public int insertOrUpdateBatch(List<ElderInfo> entities) {
        return elderInfoDao.insertOrUpdateBatch(entities);
    }

    @Override
    public List<ElderInfo> queryAllByifcare() {
        return elderInfoDao.queryAllByifcare();
    }

    @Override
    public int update(ElderInfo elderInfo) {
        return elderInfoDao.update(elderInfo);
    }

    @Override
    public int deleteById(Integer id) {
        return elderInfoDao.deleteById(id);
    }

    @Override
    public List<ElderInfo> queryElderInfoBystaffId(int staffId) {
        return elderInfoDao.queryBystaffId(staffId);
    }

    @Override
    public List<ElderInfo> queryElderInfoByCare(int ifcare) {
        return elderInfoDao.queryElderInfoByCare(ifcare);
    }

    /**
     * 护工分配老人
     *
     * @param elderDto 传入老人ID 和员工ID
     * @return 是否成功
     */
    @Override
    public boolean updateCondition(ElderDto elderDto) {
        ElderInfo elderInfo = elderInfoDao.selectById(elderDto.getId());
        if (elderInfo != null) {
            elderDto.setIfcare(1);
        }
        return elderInfoDao.updateCondition(elderDto);
    }

    /**
     * 通过老人ID，取消分配的护工
     *
     * @param elderDto
     * @return
     */
    @Override
    public boolean unassignSeniors(ElderDto elderDto) {
        ElderInfo elderInfo = elderInfoDao.conditionsSelectByid(elderDto.getId());
        if (elderInfo != null) {
            return elderInfoDao.unassignSeniors(elderDto);
        }
        return false;
    }
}
